package Date和DateFormat编程题;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;
import java.util.Scanner;

public class CompareBirthday {
    public static void compare(Date first, Date second){
        Objects.requireNonNull(first);
        Objects.requireNonNull(second);
        if(!(first.before(new Date()) && second.before(new Date()))) {
            System.out.println("生日必须早于当前日期");
            System.exit(0);
        }
        if(first.before(second))
            System.out.println("第一个生日小于第二个生日");
        else if(first.equals(second))
            System.out.println("第一个生日等于第二个生日");
        else
            System.out.println("第一个生日大于第二个生日");
    }

    public static void main(String[] args) throws Throwable{
        Scanner in = new Scanner(System.in);
        System.out.println("Enter first birthday:(eg.2022年06月23日");
        String b1 =in.nextLine();
        System.out.println("Enter second birthday:(eg.2022年06月23日");
        String b2 =in.nextLine();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        Date d1 = sdf.parse(b1);
        Date d2 = sdf.parse(b2);
        CompareBirthday.compare(d1,d2);
    }
}
